//
//  SHStatusToolBarView.swift
//  weibo1
//
//  Created by TownFish on 16/8/1.
//  Copyright © 2016年 TownFish. All rights reserved.
//

import UIKit

class SHStatusToolBarView: UIView {
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    //MARK: - 设置视图
    private func setupUI() {
        backgroundColor = RandomColor()
        //01 添加控件
        let retweetButton = addChildButton("timeline_icon_retweet", title: "转发")
        let commentButton = addChildButton("timeline_icon_comment", title: "评论")
        let unlikeButton = addChildButton("timeline_icon_unlike", title: "赞")
        
        let line1 = addChildLine()
        let line2 = addChildLine()
        //02 添加约束
        //转发按钮
        retweetButton.snp_makeConstraints { (make) -> Void in
            make.top.bottom.leading.equalTo(self)
            make.width.equalTo(commentButton)
        }
        //评论按钮
        commentButton.snp_makeConstraints { (make) -> Void in
            make.top.bottom.equalTo(self)
            make.leading.equalTo(retweetButton.snp_trailing)
            make.width.equalTo(unlikeButton)
        }
        //赞按钮
        unlikeButton.snp_makeConstraints { (make) -> Void in
            make.top.bottom.trailing.equalTo(self)
            make.leading.equalTo(commentButton.snp_trailing)
        }
        //分割线01
        line1.snp_makeConstraints { (make) -> Void in
            make.centerY.equalTo(self)
            make.centerX.equalTo(retweetButton.snp_trailing)
        }
        //分割线02
        line2.snp_makeConstraints { (make) -> Void in
            make.centerY.equalTo(self)
            make.centerX.equalTo(commentButton.snp_trailing)
        }
        
        
    }
    //创建分割线的方法
    func addChildLine() ->UIImageView {
        let img = UIImageView(imgName: "timeline_card_bottom_line")
        addSubview(img)
        return img
    }
    
    
    
    //创建button 公共方法
    //- parameter imgName: image
    //- parameter title: 名字
    func addChildButton(imgName: String, title: String) ->UIButton {
        //定义一个button
        let button = UIButton()
        button.setTitle(title, forState: UIControlState.Normal)
        button.setTitleColor(UIColor.darkGrayColor(), forState: UIControlState.Normal)
        button.titleLabel?.font = UIFont.systemFontOfSize(15)
        //设置背景图片
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: UIControlState.Normal)

        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background_highlighted"), forState: UIControlState.Highlighted)
        
        //设置image
        button.setImage(UIImage(named: imgName), forState: UIControlState.Normal)
        //添加控件
        addSubview(button)
        return button
    }
}
